//
//  HZMItemVC.m
//  糖糖大魔王
//
//  Created by 韩震明 on 15/11/9.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "HZMItemVC.h"

@interface HZMItemVC ()

@property(nonatomic, retain) HZMItemModel *productDic;
@property(nonatomic, retain) NSMutableArray *picArr;
@property(nonatomic, retain) UILabel *titleLabel;
@property(nonatomic, retain) UILabel *descLabel;
@property(nonatomic, retain) UIImageView *picImageView;
@property(nonatomic, retain) UILabel *priceLabel;
@property(nonatomic, retain) UIImageView *cardImageView;


@end

@implementation HZMItemVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self setNavigation];
    
    [self createView];
    
    [self createData];
}



#pragma mark - Navigation Setting
- (void)setNavigation
{
    self.navigationItem.title = @"物品详情";
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(-20, 0, 40, 40);
    [leftButton setImage:[UIImage imageNamed:@"nav_back@2x.png"] forState:UIControlStateNormal];
    [self.view addSubview:leftButton];
    [leftButton addTarget:self action:@selector(leftBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:leftButton] autorelease];
    
    self.navigationController.navigationBar.translucent = NO;
}

#pragma mark Navigationbar ButtonAction
- (void)leftBarButtonClick:(UIBarButtonItem *)leftBarButton
{
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma mark - View
- (void)createView
{
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 80, 10, WIDTH - 20, HEIGHT / 30)];
    [self.view addSubview:self.titleLabel];
    [_titleLabel release];
    self.titleLabel.font = [UIFont systemFontOfSize:18.0];
    
    self.descLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 80, HEIGHT / 20, WIDTH - 20, HEIGHT / 15)];
    [self.view addSubview:self.descLabel];
    self.descLabel.font = [UIFont systemFontOfSize:13.0];
    self.descLabel.textColor = [UIColor grayColor];
    self.descLabel.numberOfLines = 0;
    
    
    self.picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 80, 4 * HEIGHT / 17, WIDTH - 20, HEIGHT / 2)];
    [self.view addSubview:self.picImageView];
    [_picImageView release];
}



#pragma mark - create Data
- (void)createData
{
    NSDictionary *body = [NSDictionary dictionaryWithObjectsAndKeys:
                          @"1445332782.662591",                     @"app_installtime",
                          @"4.3",                                   @"app_versions",
                          @"appStore",                              @"channel_name",
                          @"bt_app_ios",                            @"client_id",
                          @"9c1e6634ce1c5098e056628cd66a17a5",      @"client_secret",
                          @"48626bf6c34cb06b1c13f62957eedac3",      @"oauth_token",
                          self.itsid,                               @"object_id",
                          @"9.1",                           @"os_versions",
                          @"0",                                     @"page",
                          @"10",                                    @"pagesize",
                          @"iPhone7%2C1",                           @"track_device_info",
                          @"2F83AC09-B470-4C43-9DEE-E0FB95B4B438",  @"track_deviceid",
                          @"1457891",                         @"track_user_id",
                          @"2",                                     @"type_id",
                          @"7",                                     @"v", nil];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:@"http://open3.bantangapp.com/comm/comments/list" parameters:body success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        NSDictionary *dic = responseObject;
        self.productDic = [[HZMItemModel alloc] init];
        [self.productDic setValuesForKeysWithDictionary:dic[@"data"][@"product"]];
        
        self.picArr = [NSMutableArray array];
        self.picArr = [HZMPic baseModelByArr:[self.productDic pic]];
        
        self.titleLabel.text = [self.productDic title];
        self.descLabel.text = [self.productDic desc];
        [self.descLabel sizeToFit];
        [self.picImageView sd_setImageWithURL:[NSURL URLWithString:[self.picArr[0] pic]] placeholderImage:[UIImage imageNamed:@"7"]];
        
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
